package net.hn.hnms.biz.meeting.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.hn.hnms.biz.meeting.domain.MeetingRoom;
import net.hn.hnms.biz.meeting.domain.ScheduleMining;
import net.hn.hnms.biz.meeting.vo.ScheduleMiningVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ScheduleMiningMapper extends BaseMapper<ScheduleMining> {


    @Update("<script>" +
            " update  hygl.schedule_mining set del_flag = '1' " +
            " where schedule_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);



    @Select("<script>" +
            "SELECT schedule_id, schedule_title_name, schedule_date, notice, notice_content, status " +
            "FROM schedule_mining " +
            "WHERE del_flag = '0' " +
            "AND mine_code = #{mineCode} " +
            "AND schedule_date <![CDATA[ >= ]]> TO_DATE(#{ym} || '-01', 'YYYY-MM-DD') " +  // 获取该月的第一天
            "AND schedule_date <![CDATA[ < ]]> (TO_DATE(#{ym} || '-01', 'YYYY-MM-DD') + INTERVAL '1 MONTH') " +  // 获取下月的第一天
            "</script>")
    List<ScheduleMiningVo> getSelectList(@Param("mineCode") String mineCode, @Param("ym") String ym);



    @Select("<script>" +
            " SELECT schedule_date, COUNT(*) AS record_count\n" +
            " FROM schedule_mining\n" +
            " WHERE del_flag = '0'\n" +
            " AND mine_code = #{mineCode} " +
            " AND schedule_date <![CDATA[ >= ]]> TO_DATE(#{ym} || '-01', 'YYYY-MM-DD') \n" +
            " AND schedule_date  <![CDATA[ < ]]> (TO_DATE(#{ym} || '-01', 'YYYY-MM-DD') + INTERVAL '1 MONTH')\n" +
            " GROUP BY schedule_date\n" +
            " ORDER BY schedule_date  " +
            "</script>")
    List<ScheduleMiningVo> selectListData(@Param("mineCode") String mineCode, @Param("ym") String ym);

}
